package pl.softech.gpw.model;

import java.util.Collection;

public class FIHelper {

    public static double[] toLow(Collection<FInstrument> fis) {
        return toLow(fis.toArray(new FInstrument[0]));
    }

    public static double[] toLow(FInstrument[] fis) {
        int size = fis.length;
        double[] ret = new double[size];

        for (int i = 0; i < size; i++) {
            ret[i] = fis[i].getLow();
        }

        return ret;
    }

    public static double[] toHigh(FInstrument[] fis) {
        int size = fis.length;
        double[] ret = new double[size];

        for (int i = 0; i < size; i++) {
            ret[i] = fis[i].getHigh();
        }

        return ret;
    }

    public static double[] toHigh(Collection<FInstrument> fis) {
        return toHigh(fis.toArray(new FInstrument[0]));
    }

    public static double[] toClose(Collection<FInstrument> fis) {
        return toClose(fis.toArray(new FInstrument[0]));
    }

    public static double[] toClose(FInstrument[] fis) {
        int size = fis.length;
        double[] ret = new double[size];

        for (int i = 0; i < size; i++) {
            ret[i] = fis[i].getClose();
        }

        return ret;
    }
    
    public static FInstrument add(FInstrument fin, double add) {
        return add(fin, (float) add);
    }
    
    public static FInstrument add(FInstrument fin, float add) {
        fin.setHigh(fin.getHigh() + add);
        fin.setLow(fin.getLow() + add);
        fin.setOpen(fin.getOpen() + add);
        fin.setClose(fin.getClose() + add);
        return fin;
    }

}
